package com.v5ba.service.impl;
import com.v5ba.entity.User;
import com.v5ba.mapper.UserMapper;
import com.v5ba.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class RequiredService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RequiredService requiredService;

    @Transactional
    public void update1(){
        User user = userMapper.selectById(1L);
        user.setAge(user.getAge()+1);
        userMapper.updateById(user);
        requiredService.update2();
        int i = 1 / 0;
    }
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    protected void update2(){
        User user = userMapper.selectById(2L);
        user.setAge(user.getAge()+1);
        userMapper.updateById(user);
    }
}
